home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / INTERRUP.SWG / 0001_BITSTUFF.PAS.pas next >
Pascal/Delphi Source File  |  1993-05-28  |  5KB  |  110 lines

  1. {
  2.  Well Percy (or is it Kerry?), I see that the regular crowd here have
  3.  shown you how bit-level thingys work.  So, I'll give you a working
  4.  example, including a Procedure to display the binary notation of any
  5.  Integer, so you can play With the inFormation they've given you. The
  6.  following Program reads & displays info from the equipment list Word
  7.  (Note: I've made [lazy] use of global Variables, do not emulate)...
  8. }
  9. (*******************************************************************)
  10. Program BitsNBytes;                 { ...or Digital Road Kill       }
  11. Uses
  12.   Dos;                              { import Intr() and Registers   }
  13. Var
  14.   NumberFDD,                        { number of floppy drives       }
  15.   InitVMode,                        { intial video mode             }
  16.   COMcount,                         { number of serial ports        }
  17.   LPTcount    : Byte;               { number of Printer ports       }
  18.   Is8087,                           { math copro installed?         }
  19.   IsMouse,                          { pointing device installed?    }
  20.   IsDMA,                            { DMA support installed?        }
  21.   IsGame,                           { game port installed?          }
  22.   IsModem     : Boolean;            { internal modem installed?     }
  23.   EqWord      : Word;               { the equipment list Word       }
  24.   Reg         : Registers;          { to access CPU Registers       }
  25. {-------------------------------------------------------------------}
  26. Function BitSet(AnyWord : Word; BitNum : Byte) : Boolean;
  27.  { return True if bit BitNum of AnyWord is 1, else False if it's 0  }
  28. begin
  29.   BitSet := (BitNum in [0..15]) and ODD(AnyWord SHR BitNum);
  30. end {BitSet};
  31. {-------------------------------------------------------------------}
  32. Procedure WriteBitWord( AnyWord : Word );   { show Word as binary   }
  33. Var
  34.   BinString : String[16];                   { represent binary bits }
  35.   MaxBit,                                   { max number of bits    }
  36.   BitNum    : Byte;                         { bits 0..15            }
  37. begin
  38.   BinString := '0000000000000000';          { default to 0          }
  39.   MaxBit := Length(BinString);              { total bit count (16)  }
  40.   For BitNum := 0 to PRED(MaxBit) do        { process bits (0..15)  }
  41.     if BitSet(AnyWord, BitNum) then
  42.       INC(BinString[MaxBit - BitNum]);
  43.   Write( BinString );                       { Write the binary Form }
  44. end {WriteBitWord};
  45. {-------------------------------------------------------------------}
  46. Procedure ProcessEquipList;     { parse equipment list Word EqWord  }
  47. Var
  48.   BitNum  : Byte;               { to check each bit                 }
  49.   EBitSet : Boolean;            { True if a BitNum is 1, else False }
  50. begin
  51.   For BitNum := 0 to 15 do
  52.   begin                                     { EqWord has 16 bits    }
  53.     EBitSet := BitSet(EqWord,BitNum);       { is this bit set?      }
  54.     Case BitNum of                          { each bit has meaning  }
  55.       0       : if EBitSet then             { if EqWord.0 is set    }
  56.                   NumberFDD := (EqWord SHR 6) and $3 + 1
  57.                 else
  58.                   NumberFDD := 0;
  59.       1       : Is8087    := EBitSet; { if math co-pro found  }
  60.       2       : IsMouse   := EBitSet; { if pointing device    }
  61.       3       : ; {reserved, do nothing}
  62.       4       : InitVMode := (EqWord SHR BitNum) and $3;
  63.       5..7    : ; {ignore}
  64.       8       : IsDMA     := EBitSet;
  65.       9       : COMcount  := (EqWord SHR BitNum) and $7;
  66.       10,11   : ; {ignore}
  67.       12      : IsGame    := EBitSet;
  68.       13      : IsModem   := EBitSet;
  69.       14      : LPTcount  := (EqWord SHR BitNum) and $7;
  70.       15      : ; {ignore}
  71.     end; {Case BitNum}
  72.   end; {For BitNum}
  73. end {ProcessEquipList};
  74. {-------------------------------------------------------------------}
  75. Function Maybe(Truth : Boolean) : String;
  76. begin
  77.   if not Truth then
  78.     Maybe := ' not '
  79.   else
  80.     Maybe := ' IS ';
  81. end {Maybe};
  82. {-------------------------------------------------------------------}
  83. begin
  84.   Intr( $11, Reg );
  85.   EqWord := Reg.AX;
  86.   WriteLn;
  87.   Write('Equipment list Word: ',EqWord,' decimal = ');
  88.   WriteBitWord( EqWord );
  89.   WriteLn(' binary');
  90.   WriteLn;
  91.   ProcessEquipList;
  92.   WriteLn('Number of floppies installed: ', NumberFDD );
  93.   WriteLn('Math-coprocessor',Maybe(Is8087),'installed' );
  94.   WriteLn('PS/2 Mouse',Maybe(IsMouse),'installed' );
  95.   Write('Initial video mode: ',InitVMode,' (' );
  96.   Case InitVMode of
  97.     0 : WriteLn('EGA, VGA, PGA)');
  98.     1 : WriteLn('40x25 colour)');
  99.     2 : WriteLn('80x25 colour)');
  100.     3 : WriteLn('80x25 monochrome)');
  101.   end;
  102.   WriteLn('DMA support',Maybe(IsDMA),'installed' );
  103.   WriteLn('Number of COMs installed: ',COMcount );
  104.   WriteLn('Game port',Maybe(IsGame),'installed' );
  105.   WriteLn('IBM Luggable modem',Maybe(IsModem),'installed');
  106.   WriteLn('Number of Printer ports: ',LPTcount );
  107. end {BitsNBytes}.
  108. (*******************************************************************)
  109.  
  110.